package com.se.common;

import java.util.ArrayList;
import java.util.List;

public class UserInformation {
    private String userName;
    private final List<Integer> ownGroup = new ArrayList<>();
    private final List<Integer> memberGroup = new ArrayList<>();
    private final List<String> AIList = new ArrayList<>();
    private final List<String> friendList = new ArrayList<>();
    private final List<String> friendRequest = new ArrayList<>();
    private static final int MAX_AI_NUM = 3;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public void addOwnGroup(int groupId) {
        ownGroup.add(groupId);
    }

    public List<Integer> getOwnGroup() {
        return ownGroup;
    }

    public String getOwnGroupAsString() {
        StringBuilder re = new StringBuilder();
        for(var i : ownGroup) {
            re.append(i);
            re.append(" ");
        }

        return re.toString();
    }

    public void setOwnGroupByString(String str) {
        if(str == null || str.isEmpty()) {
            return;
        }
        List<String> list = List.of(str.split(" "));
        ownGroup.clear();

        for(var i : list) {
            ownGroup.add(Integer.parseInt(i));
        }
    }

    public void addMemberGroup(int groupId) {
        memberGroup.add(groupId);
    }

    public List<Integer> getMemberGroup() {
        return memberGroup;
    }

    public String getMemberGroupAsString() {
        StringBuilder re = new StringBuilder();
        for(var i : memberGroup) {
            re.append(i);
            re.append(" ");
        }

        return re.toString();
    }

    public void setMemberGroupByString(String str) {
        if(str == null || str.isEmpty()) {
            return;
        }
        List<String> list = List.of(str.split(" "));
        memberGroup.clear();

        for(var i : list) {
            memberGroup.add(Integer.parseInt(i));
        }
    }

    public List<String> getFriendRequest() {
        return friendRequest;
    }

    public String getFriendRequestAsString() {
        StringBuilder re = new StringBuilder();
        for(var i : friendRequest) {
            re.append(i);
            re.append(" ");
        }

        return re.toString();
    }

    public void setFriendRequestByString(String str) {
        if(str == null || str.isEmpty()) {
            return;
        }

        List<String> list = List.of(str.split(" "));
        friendRequest.clear();
        friendRequest.addAll(list);
    }

    public void addFriendRequest(String userName) {
        for(var i : friendRequest) {
            if(i.equals(userName)) {
                return;
            }
        }
        friendRequest.add(userName);
    }

    public List<String> getFriendList() {
        return friendList;
    }

    public void addFiend(String friend) {
        friendList.add(friend);
    }

    public void setFriendListByString(String str) {
        if(str == null || str.isEmpty()) {
            return;
        }

        List<String> list = List.of(str.split(" "));
        friendList.clear();
        friendList.addAll(list);
    }

    public String getFriendListAsString() {
        StringBuilder re = new StringBuilder();
        for(var i : friendList) {
            re.append(i);
            re.append(" ");
        }

        return re.toString();
    }

    public boolean addAI(String id) {
        if(AIList.size() < MAX_AI_NUM) {
            AIList.add(id);
            return true;
        }

        return false;
    }

    public List<String> getAIList() {
        return AIList;
    }

    public String getAIListAsString() {
        StringBuilder re = new StringBuilder();
        for(var i : AIList) {
            re.append(i);
            re.append(" ");
        }

        return re.toString();
    }

    public void setAIListByString(String str) {
        if(str == null || str.isEmpty()) {
            return;
        }
        AIList.clear();
        AIList.addAll(List.of(str.split(" ")));
    }
}
